<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/9-16:33
 * Link: https://gitee.com/luckygyl/luckyAdmin
 * FileName: index.html
 *-->

{include file="public/head" /}

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md12">

            <?php echo Form::Search('title','栏目名称','请输入名称');?>

            <!--右侧表格开始-->
            <div class="layui-card">
                <div class="layui-card-header" style="line-height: 55px;">
                    <div class="layui-btn-container do_btn">
                        <button class="layui-btn layui-btn-sm layui-btn-danger"  data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn layui-btn-sm" data-type="add_menu"> <i class="layui-icon">&#xe61f;</i>新增栏目</button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary"  data-type="reload"> <i class="fa fa-refresh"></i> 刷新</button>
                        <button class="layui-btn layui-btn-sm layui-btn-warm"   data-type="move"> <i class="layui-icon layui-icon-add-circle"></i>新增外部链接</button>
                    </div>
                </div>
                <div class="layui-card-body">

                    <div class="yys-fluid yys-wrapper">
                        <div class="layui-row lay-col-space20">
                            <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                                <section class="yys-body">
                                    <div class="yys-body-content clearfix changepwd">
                                        <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                            <div class="user-tables">
                                                <table id="tableFilter" lay-filter="tableFilter"> </table>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!--右侧表格结束-->

        </div>


    </div>




</div>

<!--模板-->
<script type="text/html" id="operationTpl">

    {{# if (d.model_id != '7' ){ }}
    <a href="javascript:;"   class="layui-btn layui-btn-xs "  onmouseover="tis(this)"  data-title="新增子栏目" lay-event="add"><i class="layui-icon layui-icon-add-circle-fine"></i></a>
    {{# } }}

    {{# if (d.model_id != '7' ){ }}
      <a href="javascript:;"   class="layui-btn layui-btn-normal layui-btn-xs "  onmouseover="tis(this)"  data-title="编辑栏目" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    {{# }else{ }}
       <a href="javascript:;"   class="layui-btn layui-btn-normal layui-btn-xs "  onmouseover="tis(this)"  data-title="编辑栏目1" lay-event="edit1"><i class="layui-icon">&#xe642;</i></a>
    {{# } }}

    <a href="javascript:;"   class="layui-btn layui-btn-danger layui-btn-xs "  onmouseover="tis(this)"  data-title="删除栏目" lay-event="del"><i class="layui-icon " >&#xe640;</i></a>

</script>


<script type="text/html" id="status">
    <input type="checkbox" name="status"  lay-data="{{d.status}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="是|否"  {{ d.status == 1 ? 'checked' : '' }}>
</script>


{include file="public/js" /}


<script>

    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util','tree'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var tree=layui.tree;
        var util=layui.util;

        form.render();


        String.prototype.format = function () {
            //字符串占位符
            //eg: var str1 = "hello {0}".format("world");
            if (arguments.length == 0) return this;
            var param = arguments[0];
            var s = this;
            if (typeof (param) == 'object') {
                for (var key in param) {
                    s = s.replace(new RegExp("\\{" + key + "\\}", "g"), param[key]);
                }
                return s;
            } else {
                for (var i = 0; i < arguments.length; i++) {
                    s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
                }
                return s;
            }
        };

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('navigate/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:50
                ,limits:[50,60,70,80,90,100]
            },
            //height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'id',  title: 'ID',width:60,sort:true},
                {field: 'title_show', minWidth: 200, title: '栏目名称'},
                {
                    field: 'icon', width: 150, align: 'center', templet: function (d) {
                        if (d.icon == "") {
                            return '';
                        } else {
                            var a= ('<i class="{0} {1} " ></i>').format(d.fontFamily,d.icon);
                            return a;
                        }
                    }, title: '栏目图标'
                },
                {field:'is_menu',title:'是否显示',templet: '#status',width:150 ,unresize: true,sort:true},
                {field: 'href',style:'cursor: pointer;',title: '栏目url',width:270,edit:"text"},
                {field: 'name',style:'cursor: pointer;',title: '栏目模型',width:110},
                {field: 'listorder',style:'cursor: pointer;',title: '排序',width:110,edit:'number',sort:true},

                {field: 'time_formt', title: '添加时间',align: 'center',width:200,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 230, align: 'center', title: '操作'}
            ]],

            done: function (res) {
                layer.closeAll('loading');
            }
        });

        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            CreateSearch("table_id",obj.field); //查询
            return false;
        });



        /**
         * 监听是否显示操作
         */
        form.on('switch(sexDemo)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=2;
            }else {
                status=1;
            }
            change_status("table_id","navigate",_id,"status",status, obj.othis);
        });

        /**
         * 监听单元格编辑
         */
        table.on('edit(tableFilter)',function (obj) {
            var val=obj.value,_id=obj.data.id,field=obj.field;
            if (field=="href"){

            } else {
                var reg=/^[0-9]*$/;
                if (!reg.test(val)) {
                    layer.msg("排序必须是数字",{time:1000});
                    CreateReload("table_id");
                    return false;
                }
            }
            change_status("table_id","navigate",_id,field,val);

        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent==="add"){

                var url="/index.php/admin/navigate/AddNavigate/id/"+_id;
                CreateForm("添加子栏目",'50%','80%',url,"table_id");

            }else if(layEvent==="edit"){

                var urls="/index.php/admin/navigate/EditNavigate/id/"+_id;
                CreateForm("编辑栏目",'50%','80%',urls,"table_id");

            } else if(layEvent==="edit1"){

            var urls="/index.php/admin/navigate/EditLink/id/"+_id;
            CreateForm("编辑外部链接",'50%','80%',urls,"table_id");

            }
            else if(layEvent==="del"){
                delete_data(_id,"{:url('navigate/delete')}","table_id");
            }

        });


        var active = {
            add_menu:function(){
                CreateForm("添加栏目",'50%','80%',"{:url('navigate/AddNavigate')}","table_id");
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                delete_data(id,"{:url('navigate/delete')}","table_id");
            },
            reload: function(){
                CreateReload("table_id");
            },
            move:function () {
                CreateForm("新增外部链接",'50%','80%',"{:url('navigate/Addlink')}","table_id");
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


</body >
</html >